home *** CD-ROM | disk | FTP | other *** search
- /*
- * quick-n-dirty class for the Objects-in-C tester
- *
- * Copyright © John Wainwright 1988
- *
- */
-
- #include "oic.h"
- #include "generics.h"
-
- typedef struct /* coord IVs */
- {
- float x;
- float y;
- } coord_i;
- typedef object coord;
-
- class Coord;
-
- /* ------------------------------ Coord Ops -------------------------- */
-
- static coord
- _new(self, c, args)
- coord self;
- coord_i *c;
- struct
- {
- double x;
- double y;
- } *args;
- {
- c->x = args->x;
- c->y = args->y;
- return Super(self);
- }
-
- static coord
- _offset(self, c, args)
- coord self;
- coord_i *c;
- struct { double dx, dy; } *args;
- {
- c->x += args->dx;
- c->y += args->dy;
- return self;
- }
-
- static int
- _xCoord(self, c)
- coord self;
- coord_i *c;
- {
- return c->x;
- }
-
- static int
- _yCoord(self, c)
- coord self;
- coord_i *c;
- {
- return c->y;
- }
-
- static string
- _replist(self, c)
- coord self;
- coord_i *c;
- {
- char s[100];
-
- sprintf(s, "[%.2f, %.2f]", c->x, c->y);
- return New(String, s);
- }
-
- /* ------------------------------ Init Class ----------------------- */
-
- defGeneric(xCoord, xCoordGeneric, "xCoord")
- defGeneric(yCoord, yCoordGeneric, "yCoord")
- externGeneric(offset, offsetGeneric)
-
- InitCoordClass()
- {
- Coord = NewClass(sizeof(coord_i), 0, "Coord", IndexMixin, END);
- AddMethods(Coord,
- newGeneric, _new,
- offsetGeneric, _offset,
- repListGeneric, _replist,
- xCoordGeneric, _xCoord,
- yCoordGeneric, _yCoord,
- END);
- }
-